﻿
Public Class FrmPrincipal


#Region "FrmPrincipal"

    Private Property btnSelected As String

    Private Sub FrmPrincipal_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'GetFitDataSet.Usuarios' table. You can move, or remove it, as needed.
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None 'Elimina los bordes del formulario
        Me.WindowState = FormWindowState.Maximized 'Maximiza el formulario

        For Each panel As Panel In paneMenu.Controls.OfType(Of Panel)()
            AddHandler panel.MouseDown,
            Function(senderObj, args) Seleccionar(panel)
            AddHandler panel.MouseMove,
            Function(senderObj, args) Sombrear(panel)
            AddHandler panel.Click,
            Function(senderObj, args) DarFuncion(panel)
            For Each ctr As Control In panel.Controls
                AddHandler ctr.MouseDown,
                Function(senderObj, args) Seleccionar(panel)
                AddHandler ctr.MouseMove,
                Function(senderObj, args) Sombrear(panel)
                AddHandler ctr.Click,
                Function(senderObj, args) DarFuncion(panel)
            Next
        Next

        bnUserFunction()

        validarPermisos()
        perfil()

    End Sub

    Private Function Seleccionar(ppanel As Panel) As Object
        For Each panel As Panel In paneMenu.Controls.OfType(Of Panel)()
            panel.BackColor = Color.FromArgb(33, 33, 33)
        Next
        ppanel.BackColor = Color.FromArgb(237, 107, 0)
        btnSelected = ppanel.Name
        Return ppanel
    End Function

    Private Function Sombrear(ppanel As Panel) As Object
        For Each panel As Panel In paneMenu.Controls.OfType(Of Panel)()
            If panel.Name <> btnSelected Then
                panel.BackColor = Color.FromArgb(33, 33, 33)
            End If
        Next
        If ppanel.Name <> btnSelected Then
            ppanel.BackColor = Color.FromArgb(61, 61, 61)
        End If
        Return ppanel
    End Function

    Private Function DarFuncion(ppanel As Panel) As Object

        paneUserControl.Controls.Clear()
        Dim frm As New Control
        Select Case ppanel.Name
            Case "btnUsuarios"
                ' Aqui se pone la funcion del boton clientes 
                frm = New frmConsultarUsuarios
            Case "btnRoles"
                frm = New frmConsultarRoles
                ' Aqui se pone la funcion del boton roles
            Case "btnEjercicios"
                ' Aqui se pone la funcion del boton ejercicios
                frm = New frmConsultarEjercicios
            Case "btnMusculos"
                ' Aqui se pone la funcion del boton musculos
            Case "btnMaquinas"
                ' Aqui se pone la funcion del boton maquinas
            Case "btnConfiguracion"
                ' Aqui se pone la funcion del boton configuracion
            Case "btnFuncionarios"
                ' Aqui se pone la funcion del boton funcionarios
            Case "btnBitacoras"
                ' Aqui se pone la funcion del boton bitacoras
            Case "btnSalir"
                Application.Exit()
        End Select
        frm.Dock = DockStyle.Fill
        paneUserControl.Controls.Add(frm)
        Return ppanel
    End Function
#End Region


#Region "btnMenu"

    Private Sub btnMenu_Click(sender As Object, e As EventArgs) Handles btnMenu.Click
        If paneMenu.Width = 70 Then 'Si el panel del menu es igual a 70 se agranda

            paneMenu.Width = 304  'Agranda el panel del menu a 304
            picLogo.Show() 'Se muestra la imagen del logo
            btnMenu.Location = New System.Drawing.Point(241, 54)

        Else 'Si el menu esta agrandado

            paneMenu.Width = 70 'Le disminuye el tamano
            picLogo.Hide() 'Esconde la imagen del logo
            btnMenu.Location = New System.Drawing.Point(18, 40)

        End If
    End Sub

  
    Private Sub btnMenu_MouseHover(sender As Object, e As EventArgs)
        btnMenu.Image = My.Resources.menu_hover 'Obtiene la imagen de la carpeta Resources y la asigna
    End Sub

    Private Sub btnMenu_MouseLeave(sender As Object, e As EventArgs)
        btnMenu.Image = My.Resources.menu_leave 'Obtiene la imagen de la carpeta Resources y la asigna
    End Sub
#End Region



    '--------------------------->Byron<----------------------------------
    '--------------------------->Byron<----------------------------------
    '--------------------------->Byron<----------------------------------
    '--------------------------->Byron<----------------------------------


#Region "Permisos"

    Public Sub validarPermisos()

        'For Each codigoPermiso As Int16 In listaPermisos
        'If (codigoPermiso = 1) Then
        btnUsuarios.Enabled = True 'habilita el boton usuario

        'ElseIf (codigoPermiso = 2) Then
        btnRoles.Enabled = True 'habilita el boton de roles

        'ElseIf (codigoPermiso = 3) Then
        btnEjercicios.Enabled = True 'habilita el boton ejercicios

        'ElseIf (codigoPermiso = 4) Then
        btnMusculos.Enabled = True 'habilita el boton musulos

        'ElseIf (codigoPermiso = 5) Then
        btnMaquinas.Enabled = True 'habilita el boton de maquinas

        'ElseIf (codigoPermiso = 6) Then
        btnConfiguracion.Enabled = True 'habilita el boton de configuracion

        'ElseIf (codigoPermiso = 7) Then
        btnFuncionarios.Enabled = True 'habilita el boton de funcionarios

        'ElseIf (codigoPermiso = 8) Then
        btnBitacoras.Enabled = True 'habilita el boton de bitacoras

        'aqui se agregan los permisos de mas que valla a tener cada usuario

        'End If
        'Next
    End Sub

#End Region


    Public Sub perfil()
        'Dim nombreCompleto As String
        'If (UsuarioActivo.PrimerNombre.Length > 20) Then
        '    If (UsuarioActivo.PrimerApellido.Length < 19) Then
        '        nombreCompleto = UsuarioActivo.PrimerNombre + " " + UsuarioActivo.PrimerApellido
        '    Else
        '        nombreCompleto = UsuarioActivo.PrimerNombre
        '    End If
        'Else
        '    nombreCompleto = UsuarioActivo.PrimerNombre + " " + UsuarioActivo.PrimerApellido
        'End If

        'lblnombreUsuario.Text = nombreCompleto
        'paneUsuario.Width = lblnombreUsuario.Width + fotoUsuario.Width + panelEspace.Width + 5

    End Sub



#Region "botonusuario"

    Private Sub bnUserFunction()

        'For Each control As Control In paneSuperior.Controls.OfType(Of Control)()
        '    If (control.Name = "paneUsuario") Then
        '        AddHandler control.MouseMove,
        '            Function(senderObj, args) SombrearbtnInicio(control)
        '        AddHandler control.MouseLeave,
        '            Function(senderObj, args) DessombrearbtnInicio(control)
        '        AddHandler control.MouseClick,
        '            Function(senderObj, args) SelecbtnInicio(control)

        '    End If

        '    For Each x As Control In paneUsuario.Controls.OfType(Of Control)()
        '        AddHandler control.MouseClick,
        '           Function(senderObj, args) SelecbtnInicio(control)
        '        AddHandler x.MouseMove,
        '            Function(senderObj, args) SombrearbtnInicio(control)
        '        AddHandler x.MouseLeave,
        '            Function(senderObj, args) DessombrearbtnInicio(control)
        '    Next
        'Next

    End Sub

    Private Function SombrearbtnInicio(ppanel As Control) As Object
        If paneUsuario.BackColor = Color.FromArgb(235, 235, 235) Then
            ppanel.BackColor = Color.FromArgb(33, 33, 33)
            lblnombreUsuario.ForeColor = Color.FromArgb(237, 107, 0)
            lblnombreUsuario.BackColor = Color.FromArgb(33, 33, 33)
        End If

        Return ppanel
    End Function


    Private Function DessombrearbtnInicio(ppanel As Control)
        If paneUsuario.BackColor = Color.FromArgb(33, 33, 33) Then
            If (paneCerrarSesion.Visible = False) Then
                ppanel.BackColor = Color.FromArgb(235, 235, 235)
                lblnombreUsuario.ForeColor = Color.FromArgb(33, 33, 33)
                lblnombreUsuario.BackColor = Color.FromArgb(235, 235, 235)
            End If
        End If
        Return ppanel
    End Function


    Private Function SelecbtnInicio(ppanel As Control)
        paneUserControl.Controls.Add(paneCerrarSesion)
        paneCerrarSesion.BringToFront()
        If paneCerrarSesion.Visible = True Then
            paneCerrarSesion.Visible = False
            panePerfil.Visible = False
            paneCerrar.Visible = False

        Else
            paneCerrarSesion.BringToFront()
            paneCerrarSesion.Visible = True
            panePerfil.Visible = True
            paneCerrar.Visible = True
        End If

        Return ppanel
    End Function

    Private Sub fotoUsuario_Click(sender As Object, e As EventArgs) Handles fotoUsuario.Click
        SelecbtnInicio(fotoUsuario)
    End Sub

    Private Sub lblnombreUsuario_Click(sender As Object, e As EventArgs) Handles lblnombreUsuario.Click
        SelecbtnInicio(lblnombreUsuario)
    End Sub

    Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click
        Me.Close()
        FrminiciarSesion.Show()
    End Sub

    Private Sub paneCerrar_MouseClick(sender As Object, e As MouseEventArgs) Handles paneCerrar.MouseClick
        Me.Close()
        FrminiciarSesion.Show()
    End Sub

#End Region

End Class


